package com.dingwei.lesyndrome.mvp.presenter;

import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.LoginBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class LoginPresenter extends basePresenter {

    private Contract.LoginView loginView;

    public LoginPresenter(Contract.LoginView view) {
        super(view);
        this.loginView = view;
    }

    public void initData(String phone, String password) {

        RequestParams rp = new RequestParams(URLS.HOST+URLS.LOGIN);
        rp.addBodyParameter("phone", phone);
        rp.addBodyParameter("password", password);
        x.http().post(rp, new myCallback(BaseActivity.context, LoginBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                LoginBean bean = (LoginBean) baseBean;
                loginView.loginSuccess(bean);
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });

    }
}
